home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 9
/
FM Towns Free Software Collection 9.iso
/
t_os
/
tool
/
vdgear
/
src
/
grp.c
< prev
next >
Wrap
Text File
|
1994-11-16
|
9KB
|
403 lines
/*
* VIDEO GEAR
* "grp.c"
* by Good-Chy
*/
#include "video.h"
FILE *fp;
char *tif_p;
int tif_flag, tif_x, tif_y;
void mos_init()
{
MOS_resolution(0,3);
MOS_writePage(0);
MOS_horizon(0,639);
MOS_vertical(0,479);
setmos(81);
MOS_disp(1);
}
void screen1()
{
EGB_init(egb_work,1536);
EGB_resolution(egb_work,0, 3); /* 16 色 */
EGB_resolution(egb_work,1,10); /* 32k色 */
EGB_resolutionRam(egb_work,0x80, 4,640,480,mvram1); /* 仮想画面1 */
EGB_resolutionRam(egb_work,0x81,16,320,240,mvram2); /* 仮想画面2 */
EGB_displayPage(egb_work,0,3); /* page0を手前に */
EGB_color(egb_work,1,0); /* 背景色を0 */
EGB_writePage(egb_work,0); /* page0の設定 */
EGB_clearScreen(egb_work);
EGB_displayStart(egb_work,2,1,1); /* 倍率1*1 */
EGB_displayStart(egb_work,3,640,480); /* 大きさ */
EGB_writePage(egb_work,1); /* page1の設定 */
EGB_clearScreen(egb_work);
EGB_displayStart(egb_work,2,2,2); /* 倍率2*2 */
EGB_displayStart(egb_work,3,320,240); /* 大きさ */
EGB_writePage(egb_work,0);
}
void main_screen_load()
{
char *p;
p = tiff_load("vdgear.sc2"); /* ウィンドウデ-タ読み込み */
EGB_writePage(egb_work,0x80);
put_vram((p+6),0,0,WORD(p+0),WORD(p+2));
free(p);
p = tiff_load("vdgear.sc3"); /* 32kデ-タ読み込み */
EGB_writePage(egb_work,0x81);
put_vram((p+6),0,0,WORD(p+0),WORD(p+2));
free(p);
p = tiff_load("vdgear.sc1"); /* メイン画面読み込み */
TIFF_getPal(pal_buff);
EGB_palette(egb_work, 0, pal_buff);
EGB_writePage(egb_work,0);
put_vram((p+6),0,0,WORD(p+0),WORD(p+2));
free(p);
sprint("V2.1b 1993 by Good-Chy",438,458,15,0,16,16,9);
}
void screen2()
{
MOS_disp(0);
EGB_resolution(egb_work,0,11); /* 32k色 */
EGB_resolution(egb_work,1,11); /* 32k色 */
EGB_resolutionRam(egb_work,0x80,16,320,240,mvram2); /* 仮想画面1 */
EGB_displayPage(egb_work,0,3); /* page0を手前に */
EGB_color(egb_work,1,0x8000); /* 背景色を0x8000 */
EGB_writePage(egb_work,0); /* page0の設定 */
EGB_clearScreen(egb_work);
EGB_displayStart(egb_work,2,4,1); /* 倍率4*1 */
EGB_displayStart(egb_work,3,320,240); /* 大きさ */
EGB_writePage(egb_work,1); /* page1の設定 */
EGB_clearScreen(egb_work);
EGB_displayStart(egb_work,2,4,1); /* 倍率4*1 */
EGB_displayStart(egb_work,3,320,240); /* 大きさ */
EGB_writePage(egb_work,0);
}
int read_data(char *bp, int size) /* tiffをファイルから読み込む */
{
if (fread(bp, 1, size, fp) != size )
{ return -1; }
return 0;
}
int put_data(char *buf, int lofs, int lines ) /* tiffをメモリに蓄える */
{
int i, j, sx;
if (tif_flag == 16) /* 16色 */
{ sx = tif_x/2; }
else /* 32k色 */
{ sx = tif_x*2; }
for (i=0 ; i<lines ; i++)
{
for (j=0 ; j<sx ; j++)
{
*(tif_p+(i+lofs)*sx+j + 6) = *(buf+i*sx+j);
}
}
return 0;
}
char *tiff_load(char *file_name)
{
char *load_buff, *save_buff, *comp_buff;
int load_buf_size, save_buf_size, bit_pix, line_size;
int comp,fill;
long strip, clut, width;
err = 0;
MOS_disp(0); /* マウスを時計に */
setmos(82);
MOS_disp(1);
load_buf_size = 1024*150; /* バッファサイズ */
save_buf_size = 1024*150;
load_buff = malloc( load_buf_size ); /* ロードバッファ */
save_buff = malloc( save_buf_size ); /* 展開バッファ */
comp_buff = malloc( DECOMP_WORK_SIZE ); /* 圧縮展開用ワーク */
if ((fp = fopen(file_name, "rb")) == NULL) /* ファイルオープン */
{ err = 1; return NULL; }
fread(load_buff, 1, load_buf_size, fp); /* 最初のデータロード */
if (TIFF_getHead(load_buff, load_buf_size)<0) /* ヘッダの解析 */
{ err = 2; return NULL; }
if ((bit_pix = TIFF_checkMode(&tif_x,&tif_y,&comp,&fill,&strip,&clut))<0)
{ err = 2; return NULL; }
if ((bit_pix == 24) || (bit_pix == 8)) /* 1600万色,256色 */
{ err = 3; return NULL; }
TIFF_setLoadFunc(put_data, read_data); /* 関数の定義 */
width = tif_x;
if (bit_pix == 4)
{
if (width & 7) { width += 8 - (width & 7); }
}
line_size = save_buf_size / ((width * bit_pix + 7)/ 8);
/* バッファに入る行数 */
if (bit_pix == 4) /* 16色モ-ド */
{
tif_flag = 16;
tif_p = malloc((tif_x+8)/8*4*(tif_y+1));
}
else /* 32k色モ-ド */
{
tif_flag = 32;
tif_p = malloc((tif_x+1)*2*(tif_y+1));
}
WORD(tif_p + 0) = tif_x-1;
WORD(tif_p + 2) = tif_y-1;
WORD(tif_p + 4) = bit_pix;
/* TIFFデータの読込 */
TIFF_loadImage(bit_pix, tif_x,tif_y, strip, fill, comp,
save_buff, width, line_size, comp_buff);
free(load_buff);
free(save_buff);
free(comp_buff);
fclose(fp);
MOS_disp(0); /* マウスを矢印に */
setmos(81);
MOS_disp(1);
return(tif_p);
}
int write_data(char *buf, long size)
{
if (fwrite(buf, 1, size, fp) != size )
{ return -1; }
return 0;
}
int get_data(char *buf, int ofs, int lines)
{
int i,j;
for (i=0 ; i<lines ; i++)
{
for (j=0 ; j<tif_x*2 ; j++)
{
*(buf+i*tif_x*2+j) = *(tif_p+(i+ofs)*tif_x*2+j);
}
}
return 0;
}
void tiff_save(char *file_name, char *buf, int x, int y)
{
char *imag_buff, *save_buff, *comp_buff;
int imag_buf_size, save_buf_size, line_size;
long tiff_size;
err = 0;
MOS_disp(0); /* マウスを時計に */
setmos(82);
MOS_disp(1);
imag_buf_size = 1024*150; /* バッファサイズ */
save_buf_size = 1024*150;
imag_buff = malloc( imag_buf_size ); /* イメ-ジバッファ */
save_buff = malloc( save_buf_size ); /* セ-ブバッファ */
comp_buff = malloc( COMP_WORK_SIZE ); /* 圧縮展開用ワーク */
if ((fp = fopen(file_name, "wb")) == NULL) /* ファイルオープン */
{ err = 1; }
fseek(fp,512,0);
tif_p = buf;
tif_x = x;
tif_y = y;
TIFF_setSaveFunc(write_data, get_data);
line_size = imag_buf_size / (x*2);
TIFF_saveImage(16,x,y,5,save_buff,save_buf_size,imag_buff,x,line_size,comp_buff);
tiff_size = ftell(fp)-512;
TIFF_setHead(save_buff,16,x,y,tiff_size,NULL);
rewind(fp);
fwrite(save_buff,1,512,fp);
free(imag_buff);
free(save_buff);
free(comp_buff);
fclose(fp);
MOS_disp(0); /* マウスを矢印に */
setmos(81);
MOS_disp(1);
}
void sprint(char *str, int x, int y, int c1, int c2,
int vx, int vy, int sty)
{
EGB_textZoom(egb_work,0,vx/2,vy);
EGB_textZoom(egb_work,1,vx,vy);
EGB_fontStyle(egb_work,sty);
EGB_color(egb_work,0,c1);
EGB_color(egb_work,1,c2);
WORD(para+0) = x;
WORD(para+2) = y;
WORD(para+4) = strlen(str);
strcpy((char *)(para+6),str);
MOS_disp(0);
EGB_sjisString(egb_work,para);
MOS_disp(1);
}
void sprintusing(int obj, int keta, int x, int y, int c1, int c2,
int vx, int vy, int sty)
{
char sstr[10];
int i,j;
i = keta-1;
for (j=0 ; j<9 ; j++) { sstr[j] = ' '; }
sstr[keta] = '\0';
while((obj>9) && (i>0))
{
sstr[i] = '0' + (obj % 10);
obj /= 10;
i--;
}
sstr[i] = '0' + obj;
sprint(sstr,x,y,c1,c2,vx,vy,sty);
}
void box_full(int x1, int y1, int x2, int y2, int c1, int c2, int func)
{
EGB_color(egb_work,0,c1); /* 枠の色 */
EGB_color(egb_work,2,c2); /* 中塗り色 */
EGB_writeMode(egb_work,func); /* 描写モ-ド */
WORD(para+0) = x1;
WORD(para+2) = y1;
WORD(para+4) = x2;
WORD(para+6) = y2;
MOS_disp(0);
EGB_rectangle(egb_work,para);
MOS_disp(1);
}
char *get_vram(int flag,int x1, int y1, int x2, int y2)
{
char *p;
if (flag == 16) /* 16色モ-ド */
{ p = malloc((x2-x1+8)/8*4*(y2-y1+1)); }
else /* 32k色モ-ド */
{ p = malloc((x2-x1+1)*2*(y2-y1+1)); }
EGB_writeMode(egb_work,0);
DWORD(para+ 0) = (unsigned int)p;
WORD(para+ 4) = getds();
WORD(para+ 6) = x1;
WORD(para+ 8) = y1;
WORD(para+10) = x2;
WORD(para+12) = y2;
MOS_disp(0);
EGB_getBlock(egb_work, para);
MOS_disp(1);
return p;
}
void put_vram(char *p, int x1, int y1, int x2, int y2)
{
EGB_writeMode(egb_work,0);
DWORD(para+ 0) = (unsigned int)p;
WORD(para+ 4) = getds();
WORD(para+ 6) = x1;
WORD(para+ 8) = y1;
WORD(para+10) = x2;
WORD(para+12) = y2;
MOS_disp(0);
EGB_putBlock(egb_work, 0, para);
MOS_disp(1);
}
void put_vram_zoom(char *p, int x1, int y1, int x2, int y2, int dx, int dy)
{
EGB_writeMode(egb_work,0);
DWORD(para+ 0) = (unsigned int)p;
WORD(para+ 4) = getds();
WORD(para+ 6) = x1;
WORD(para+ 8) = y1;
WORD(para+10) = x2;
WORD(para+12) = y2;
WORD(para+14) = dx;
WORD(para+16) = dy;
MOS_disp(0);
EGB_putBlockZoom(egb_work, 0, para);
MOS_disp(1);
}
void scroll(int x1, int y1, int x2, int y2, int vx, int vy)
{
WORD(para+0) = x1;
WORD(para+2) = y1;
WORD(para+4) = x2;
WORD(para+6) = y2;
EGB_partScroll(egb_work, 0, vx, vy, para);
}
void line(int x1, int y1, int x2, int y2, int c1)
{
EGB_color(egb_work,0,c1);
WORD(para+0) = 2;
WORD(para+2) = x1;
WORD(para+4) = y1;
WORD(para+6) = x2;
WORD(para+8) = y2;
MOS_disp(0);
EGB_connect(egb_work,para);
MOS_disp(1);
}
void set_palette(int i, char r, char g, char b)
{
DWORD(para+ 0) = 1;
DWORD(para+ 4) = i;
BYTE(para+ 8) = b;
BYTE(para+ 9) = r;
BYTE(para+10) = g;
BYTE(para+11) = 0;
EGB_palette(egb_work,1,para);
}
void wait_vsync()
{
DWORD(para+0) = 0;
EGB_palette(egb_work,1,para);
}